package top.jolyoulu.codegenweb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.jolyoulu.codegenweb.entity.bo.form.DataSourceInfoFormBO;
import top.jolyoulu.codegenweb.entity.bo.query.DataSourceInfoQueryBO;
import top.jolyoulu.codegenweb.entity.vo.DataSourceInfoVO;
import top.jolyoulu.codegenweb.service.bll.ApiDataSourceService;
import top.jolyoulu.modules.mybatisplusmodule.plugin.page.JlPage;
import top.jolyoulu.webcommon.entity.ResultInfo;

import java.util.List;

/**
 * 数据源管理
 */
@RestController
@RequestMapping("/api/data/source")
public class ApiDataSourceController {

    @Autowired
    private ApiDataSourceService apiDataSourceService;

    /**
     * 列表查询
     */
    @GetMapping("/list")
    public ResultInfo<JlPage<DataSourceInfoVO>> list(DataSourceInfoQueryBO bo){
        JlPage<DataSourceInfoVO> res = apiDataSourceService.pageList(bo);
        return ResultInfo.success(res);
    }

    /**
     * 信息
     */
    @GetMapping("/get/{id}")
    public ResultInfo<DataSourceInfoVO> getById(@PathVariable String id) {
        DataSourceInfoVO res = apiDataSourceService.getById(id);
        return ResultInfo.success(res);
    }

    /**
     * 添加
     */
    @PostMapping("/add")
    public ResultInfo add(@RequestBody @Validated DataSourceInfoFormBO bo){
        apiDataSourceService.add(bo);
        return ResultInfo.success();
    }

    /**
     * 修改
     */
    @PutMapping("/edit/{id}")
    public ResultInfo edit(@PathVariable String id,@RequestBody DataSourceInfoFormBO bo){
        bo.setId(id);
        apiDataSourceService.update(bo);
        return ResultInfo.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/del")
    public ResultInfo del(@RequestBody List<String> ids){
        apiDataSourceService.delByIds(ids);
        return ResultInfo.success();
    }
}
